package com.zoe.app.service;

import cn.hutool.core.util.IdUtil;
import com.zoe.app.context.OrderContext;
import com.zoe.app.domain.Order;
import com.zoe.app.filters.IBaseFilterChain;
import com.zoe.app.plugins.BasePlugin;
import com.zoe.app.selectors.FilterSelectorFactory;
import com.zoe.app.selectors.IFilterSelector;
import lombok.RequiredArgsConstructor;
import org.springframework.plugin.core.PluginRegistry;
import org.springframework.stereotype.Service;

/**
 * @author zbg
 * @date 2023/06/06
 * @description
 */
@Service
@RequiredArgsConstructor
public class OrderService {

    private final PluginRegistry<BasePlugin, Order> pluginRegistry;
    private final IBaseFilterChain<OrderContext> orderChain;

    public void calcOrder() {
        IFilterSelector filterSelector = FilterSelectorFactory.of()
                                                              .getFilterSelector("yw1");
        Order order = new Order();
        order.setBigDecimal(100);
        order.setOrderNo(IdUtil.fastSimpleUUID());
        OrderContext orderContext = new OrderContext(filterSelector)
                .setOrder(order);
        orderChain.fireFilter(orderContext);

        for (BasePlugin basePlugin : pluginRegistry.getPluginsFor(order)) {
            basePlugin.handleModel(order);
        }
    }
}
